from .relys import BitSet
from .relys import Chip

class HLTError(Exception):
    def __init__(self, word="HLT"):
        pass
    def __str__(self):
        return "HLT"

class Timer(Chip):
    def __init__(self, step=False):
        super().__init__(3, [0], [1, 3])
        self.step = step
        self.HLT = self._ref@[0]
        self.CLK = self._ref@[1]
        self.NCLK = self._ref@[2]

@Timer.keyframe(0)
def _frame(chip):
    if ~chip.HLT() : 
        if chip.step : input("- PRESS ENTER -")
        chip.CLK(~chip.CLK())
        chip.NCLK(~chip.CLK())
    else : raise HLTError()
    return chip

# @Timer.keyframe(-1)
# def _frame(chip):
#     input("- PRESS ENTER -")
#     return chip

# module test
if __name__ == "__main__":
    t = Timer()
    for i in range(Timer.maxframe+1) : 
        t.update(i)
        print(f"<frame>:[{i}]", t)
